package ooday04;



import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {
//    超类型的引用指向派生类类的对象
//    能点出来什么看引用 及左边的类型
//
    public static void main(String[] args) {
     /*   Master master = new Master();

        Dog dog=new Dog("1",2,"3");
        Fish fish=new Fish("2",3,"4");
        Chick chick=new Chick("3",4,"5");
        master.feed(dog);//自动向上造型*/

//    List<Animal> A=new ArrayList<>();
//      A.add(0,new Dog("a",2,"a"));
//      A.add(1,new Fish("a",2,"a"));
//      A.add(2,new Chick("a",2,"a"));
//        Iterator<Animal> iterator = A.iterator();
//        while (iterator.hasNext()) {
//            Animal next =  iterator.next();
//            System.out.println(next.name);
//        }
        Animal[] animals=new  Animal[3];
        animals[0]=new Dog("1",2,"3");
        animals[1]=new Fish("2",3,"4");
        animals[2]=new Chick("3",4,"5");
        for (int i = 0; i <animals.length ; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                Dog dog= (Dog) animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick= (Chick) animals[i];
               chick.layEggs();
            }
            if (animals[i] instanceof Fish){
                Fish fish= (Fish) animals[i];
//                fish.swimming();
            }
            if (animals[i] instanceof swim){
                swim s= (swim) animals[i];
               s.swimming();
            }
            System.out.println("================");
        }

        Animal a=new Dog("1",2,"3");
        Dog dog= (Dog) a;
        swim swim=(swim)a;
        System.out.println("======");
        System.out.println(Math.random());
}
}
